<?php

class match extends Model {
	private $_Player1;
	private $_Player2;
	private $_Player3;
	private $_Player4;
	private $_Surface;
	private $_Result;
	private $_Type;
	
	private function _setDefaultValues($arrInitialValues = null){
		if (isset($arrInitialValues['type']) && !empty($arrInitialValues['type']))
			$this->setType($arrInitialValues['type']);
		else 
			$this->setType('S');
			
		if (isset($arrInitialValues['player1_id']) && !empty($arrInitialValues['player1_id']))
			$this->setPlayer1(new Player(
				array(
					'id' => $arrInitialValues['player1_id'])
				)
			);
		else 
			$this->setPlayer1(new Player());
			
		if (isset($arrInitialValues['player2_id']) && !empty($arrInitialValues['player2_id']))
			$this->setPlayer2(new Player(array(
					'id' => $arrInitialValues['player2_id'])
				)
			);
		else 
			$this->setPlayer2(new Player());

		if (isset($arrInitialValues['player3_id']) && !empty($arrInitialValues['player3_id']))
			$this->setPlayer3(new Player(array(
					'id' => $arrInitialValues['player3_id'])
				)
			);
		else 
			$this->setPlayer3(new Player());
			
			
		if (isset($arrInitialValues['player4_id']) && !empty($arrInitialValues['player4_id']))
			$this->setPlayer4(new Player(array(
					'id' => $arrInitialValues['player4_id'])
				)
			);
		else 
			$this->setPlayer4(new Player());
			
		if (isset($arrInitialValues['result']) && !empty($arrInitialValues['result']))
			$this->setResult($arrInitialValues['result']);
		else 
			$this->setResult('');
	}
	
	
	/**
	 * @return the $_Type
	 */
	public function getType() {
		return $this->_Type;
	}

	/**
	 * @param field_type $_Type
	 */
	public function setType($_Type) {
		$this->_Type = $_Type;
	}

	public function __construct($arrInitialValues = null){
		$this->setTable('matches');
		$this->setColumnId('match_id');

		$this->_setDefaultValues($arrInitialValues);
		parent::__construct($arrInitialValues);
	}
	
	public function getAllFromSerie($serie_id){
		$query = '
			SELECT *
			FROM international_matches
			WHERE serie_id = ' . $serie_id;

		$dbHelper = new DBHelper($query);
		return $dbHelper->getResult();
	}
	
	/**
	 * @return the $_Player3
	 */
	public function getPlayer3() {
		return $this->_Player3;
	}

	/**
	 * @return the $_Player4
	 */
	public function getPlayer4() {
		return $this->_Player4;
	}

	/**
	 * @return the $_Surface
	 */
	public function getSurface() {
		return $this->_Surface;
	}

	/**
	 * @param field_type $_Player3
	 */
	public function setPlayer3($_Player3) {
		$this->_Player3 = $_Player3;
	}

	/**
	 * @param field_type $_Player4
	 */
	public function setPlayer4($_Player4) {
		$this->_Player4 = $_Player4;
	}

	/**
	 * @param field_type $_Surface
	 */
	public function setSurface($_Surface) {
		$this->_Surface = $_Surface;
	}

	public function getPlayer1(){
		return $this->_Player1;
	}

	public function getPlayer2(){
		return $this->_Player2;
	}

	public function getResult(){
		return $this->_Result;
	}

	public function setPlayer1($value){
		$this->_Player1 = $value;
	}

	public function setPlayer2($value){
		$this->_Player2 = $value;
	}

	public function setResult($value){
		$this->_Result = $value;
	}
}

?>